FROM {{ namespace }}/{{ image_prefix }}nova-base:{{ tag }}
MAINTAINER {{ maintainer }}

{% import "macros.j2" as macros with context %}

{% if base_distro in ['centos', 'fedora', 'oraclelinux', 'rhel'] %}

    {% set nova_libvirt_packages = [
        'libvirt-daemon',
        'libguestfs',
        'qemu-system-x86',
        'libvirt-daemon-driver-nwfilter',
        'libvirt-daemon-config-nwfilter',
        'libvirt-daemon-driver-lxc',
        'ceph-common'
    ] %}

{% elif base_distro == 'ubuntu' %}

    {% set nova_libvirt_packages = [
        'ceph-common',
        'libvirt-bin',
        'dmidecode',
        'pm-utils',
        'qemu',
        'qemu-block-extra',
        'ebtables',
        'xen-utils-4.6'
    ] %}

    {% set libvirt_group = 'libvirtd' %}

{% elif base_distro == 'debian' %}

    {% set nova_libvirt_packages = [
        'ceph-common',
        'libvirt-bin',
        'dmidecode',
        'pm-utils',
        'qemu',
        'qemu-block-extra',
        'ebtables',
        'xen-utils-4.4',
        'usermode'
    ] %}

    {% set libvirt_group = 'libvirt' %}

{% endif %}

{{ macros.install_packages(nova_libvirt_packages | customizable("packages")) }}

{% if base_distro in ['centos', 'fedora', 'oraclelinux', 'rhel'] %}

RUN usermod -a -G nova qemu

{% elif base_distro in ['ubuntu', 'debian'] %}

RUN mkdir -p /etc/ceph \
    && rm -f /etc/libvirt/qemu/networks/default.xml \
        /etc/libvirt/qemu/networks/autostart/default.xml \
    && usermod -a -G {{ libvirt_group }} nova

{% endif %}

COPY extend_start.sh /usr/local/bin/kolla_extend_start
RUN chmod 755 /usr/local/bin/kolla_extend_start

{% block nova_libvirt_footer %}{% endblock %}
{% block footer %}{% endblock %}
{{ include_footer }}
